package com.gjt.listener.impl;

import com.gjt.annotation.ClassAnnotation;
import com.gjt.enmuns.AnnotationEventType;
import com.gjt.event.RootEvent;
import com.gjt.event.impl.InsertEventImpl;
import com.gjt.listener.RootEventListener;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;

@Component
public class DataOptionListenerImpl implements RootEventListener {
    @Override
    public void onListener(Object object) {
        Annotation[] annotations = object.getClass().getAnnotations();
        int annotationId = 0;
        for (Annotation annotation : annotations) {
            if (annotation instanceof ClassAnnotation) {
                ClassAnnotation annotation1 = (ClassAnnotation) annotation;
                annotationId = annotation1.id();
                System.out.println("annotationName:" + annotation1.value());
            }
        }


        // 发布的是更新操作事件
        if (annotationId == AnnotationEventType.INSERT.getId()) {
            InsertEventImpl insertEvent = (InsertEventImpl) object;
            insertEvent.onMessage("执行".getClass());
        }
    }
}
